package EXam.Question15;

public class Student999 implements Comparable<Student999>
    {
        private String name;
        private int physic;
        private int chemistry;

    public Student999() {
    }

    public Student999(String name, int physic, int chemistry) {
        this.name = name;
        this.physic = physic;
        this.chemistry = chemistry;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPhysic() {
        return physic;
    }

    public void setPhysic(int physic) {
        this.physic = physic;
    }

    public int getChemistry() {
        return chemistry;
    }

    public void setChemistry(int chemistry) {
        this.chemistry = chemistry;
    }

    @Override
    public String toString() {
        return "Student999{" +
                "name='" + name + '\'' +
                ", physic=" + physic +
                ", chemistry=" + chemistry +
                '}';
    }
public int getTotalScore() {
        return physic + chemistry;
}
        @Override
        public int compareTo(Student999 other) {
            int totalScoreDiff = other.getTotalScore()-this.getTotalScore();//总分从高到低排序
            if (totalScoreDiff != 0) {
                return totalScoreDiff;

            }

                return  other.getPhysic()-this.getPhysic() ;
                //this：表示将要添加进去的Student对象
                //o: 表示集合中已有的Student对象
        }
    }
